﻿package com.firewolf.fullsort;  
  
import java.util.ArrayList;  
import java.util.Arrays;  
import java.util.List;  
  
/** 
 * 递归写出排列后的串
 * 从n个不同元素中任取m（m≤n）个元素，按照一定的顺序排列起来，叫做从n个不同元素中取出m个元素的一个排列。
 * 当m＝n时所有的排列情况叫全排列
 */  
public class FullSort {    
    private static int NUM = 5;  
    private static int sum = 0;
    private static void sort(List<String> datas, List<String> target) {  
        if (target.size() == NUM) {  
            for (String obj : target)  
                System.out.print(obj);  
            System.out.println();  
            sum += 1;
            return;  
        }  
        for (int i = 0; i < datas.size(); i++) {  
            List<String> newDatas = new ArrayList<String>(datas);  
            List<String> newTarget = new ArrayList<String>(target);  
            newTarget.add(newDatas.get(i));  
            newDatas.remove(i);  
            sort(newDatas, newTarget);  
        }  
    }  
  
    public static void main(String[] args) {  
        String[] datas = new String[] { "a", "b", "c","d","e"};  
        sort(Arrays.asList(datas), new ArrayList<String>());  
        System.out.println(sum);
    }  
  
}  